package com.example.zqm.git72.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.zqm.git72.JavaBean.Contest;
import com.example.zqm.git72.Model.ContestModel;
import com.example.zqm.git72.R;
import com.squareup.picasso.Picasso;

import org.w3c.dom.Text;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class ContestDetailActivity extends AppCompatActivity {
   String id;
    private TextView contestname;
    private TextView time;
    private TextView date;
    private ImageView contestpic;
    private TextView url;
    private TextView intro;
    private Button back;
    Contest contest;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_contestdetail);
        intNN();
        initView();

    }

    public  void  initView(){
        contestname =(TextView)findViewById(R.id.contestname);
        time=(TextView)findViewById(R.id.time);
        date=(TextView)findViewById(R.id.date);
        contestpic=(ImageView)findViewById(R.id.contestpic);
        url=(TextView)findViewById(R.id.url);
        intro=(TextView)findViewById(R.id.intro);
        back=(Button)findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(ContestDetailActivity.this,MainActivity.class);
                startActivity(intent);
            }
        });

    }
    protected void intNN(){
        Intent intent=getIntent();
        Bundle bundle=intent.getExtras();
        id=bundle.getString("id");
        ContestModel contestModel =new ContestModel();
        Call<Contest> call =contestModel.getContestById(id);
        call.enqueue(new Callback<Contest>() {
            @Override
            public void onResponse(Call<Contest> call, Response<Contest> response) {
                contest=response.body();
                contestname.setText(contest.getName());
                intro.setText(contest.getIntroduction());
                time.setText(contest.getUpdate_time());
                date.setText(contest.getCdate());
                url.setText(contest.getUrl());
                String PicUrl ="http://172.24.10.175/workout/Uploads/" +contest.getThumb();
                Picasso.with(ContestDetailActivity.this).load(PicUrl.toString())
                        .resize(200,50).into(contestpic);
            }

            @Override
            public void onFailure(Call<Contest> call, Throwable t) {

            }
        });

    }


}
